package com.lwx.sort;

import java.util.Arrays;
import java.util.Random;

public class BubbleSortDemo {
    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i <10 ; i++) {
            arr[i] = new Random().nextInt(1000);
        }
        System.out.println("排序前"+ Arrays.toString(arr));
        bubbleSort(arr);
        System.out.println("排序后"+ Arrays.toString(arr));
    }

    public static void bubbleSort(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j+1] < arr[j]){
                    int tmp = arr[j+1];
                    arr[j+1] = arr[j];
                    arr[j] = tmp;
                }
            }
        }
    }
}
